<template>
  <div id="yoso">
    <el-input style="width: 170px" v-model="u_id" placeholder="用户id"></el-input>
    <el-button icon="el-icon-search" circle @click="search"></el-button>
    <el-table
      :data="page.list"
      stripe
      style="width: 100%">
      <el-table-column prop="order.o_id" label="订单号" width="180"></el-table-column>
      <el-table-column prop="order.u_id" label="用户" width="80"></el-table-column>
      <el-table-column prop="cartItem.commodity.c_name" label="商品" width="100"></el-table-column>
      <el-table-column prop="cartItem.subtotal" label="总价" width="100"></el-table-column>
      <el-table-column prop="order.o_address" label="地址" width="180"></el-table-column>
      <el-table-column prop="order.o_date" label="下单时间" width="180"></el-table-column>

      <el-table-column label="操作" prop="order.o_id">

        <template slot-scope="scope">
          <el-button type="info" round size="small" @click="toDetail(scope.row.order.c_id)">详情</el-button>
          <el-button type="danger" icon="el-icon-edit" circle @click="toUpdate(scope.row.order.o_id)"></el-button>
          <el-button type="success" round size="small" @click="send(scope.row.order.o_id)">发货</el-button>

        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page.curPage" :page-sizes="[4,8]" :page-size="page.pageSize" layout="total,sizes,prev,pager,next,jumper" :total="page.count"></el-pagination>
  </div>
</template>

<script>
  export default {
    data(){
      return{
        page:{},
        login:false,
        admin:{},
        pageSize:4,
        o_id:'',//订单号
        u_id:''//用户ID
      }
    },
    methods:{
      paging(curPage){
        this.$axios.get('/OrderServlet/listByStatus?curPage='+curPage +'&pageSize=' + this.pageSize +'&s_id=3')
          .then(resp=>{
            this.page = resp.data;
          });

      },
      search(){
        if (this.u_id===''){
          this.paging(1)
        }else {

          this.$axios.get('/OrderServlet/listByU_idAndStatus?curPage=1' +'&pageSize=' + this.pageSize +'&s_id=3'+'&u_id='+this.u_id)
            .then(resp=>{
              this.page = resp.data;
            })
        }

      },
      handleCurrentChange(newPage){
        this.paging(newPage)
      },
      handleSizeChange(newSize){
        this.pageSize = newSize;
        this.paging(1)
      },
      toUpdate(o_id){
        this.$router.push('/order/update/'+o_id)
      },
      send(o_id){

        this.$axios.post('OrderServlet/send?o_id=' + o_id)
        this.paging(1)
        this.reload();
      },
      toDetail(c_id){
        this.$router.push('/commodity/detail/'+c_id)
      }
    },
    created() {
      this.admin= this.$store.state.admin;
      this.login = this.admin.a_id !== undefined;
      if (this.login) {
        this.paging(1);
      }else {
        this.$router.push('/')
      }
    }
  }
</script>

<style scoped>

</style>
